
#创建目录
mkdir -p /usr/local/elasticsearch/config
mkdir -p /usr/local/elasticsearch/logs
mkdir -p /usr/local/elasticsearch/data
mkdir -p /usr/local/elasticsearch/plugins

#创建配置文件
touch /usr/local/elasticsearch/config/elasticsearch.yml
#追加配置内容
echo 'http.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*" '>>/usr/local/elasticsearch/config/elasticsearch.yml

#配置目录权限
chmod -R 777 /usr/local/elasticsearch/logs /usr/local/elasticsearch/data /usr/local/elasticsearch/plugins

#创建虚拟网络
docker network create somenetwork

#创建容器
docker run -d \
	--name elasticsearch-7.17.7 \
    -e "ES_JAVA_OPTS=-Xms512m -Xmx1024m" \
    -e "discovery.type=single-node" \
    -e "cluster.name=elasticsearch" \
    -v /usr/local/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
    -v /usr/local/elasticsearch/data:/usr/share/elasticsearch/data \
    -v /usr/local/elasticsearch/logs:/usr/share/elasticsearch/logs \
    -v /usr/local/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
    --privileged \
    --network somenetwork \
    -p 9200:9200 \
    -p 9300:9300 \
    --restart=unless-stopped \
elasticsearch:7.17.7


